package regulation.auto.com.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.ptjob.basecore.bean.ClientBaseBean;

import regulation.auto.com.R;
import regulation.auto.com.bean.LoginBean;
import regulation.auto.com.bean.PointBean;
import regulation.auto.com.request.AsyncCallBack;
import regulation.auto.com.request.RequestLoginTask;
import regulation.auto.com.request.RequestPointsTask;
import regulation.auto.com.util.UserManager;

public class MainActivity extends AppCompatActivity {

    String userName = "admin";
    String passWord = "123456";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView textView = (TextView) this.findViewById(R.id.tv_hello);

        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final RequestLoginTask requestLoginTask = new RequestLoginTask(MainActivity.this,
                                                                                userName,
                                                                                passWord,
                        new AsyncCallBack(){
                            @Override
                            public void update(ClientBaseBean result) {
                                LoginBean loginBean = (LoginBean) result;


                                if(loginBean != null){
                                    UserManager.getInstance().setLoginInfo(loginBean);
                                    UserManager.getInstance().setUserName(userName);
                                }

                                getPoints();

                                Log.i("geny", "result = " + loginBean.toString());
                            }

                            @Override
                            public void dataError(int type, String msg) {
                                Log.i("geny", "msg = " + msg);
                            }
                        });
                requestLoginTask.start();
            }
        });



    }


    private void getPoints(){

        
        final RequestPointsTask requestPointsTask = new RequestPointsTask(this,
                new AsyncCallBack(){
                    @Override
                    public void update(ClientBaseBean result) {
                        PointBean PointBean = (PointBean) result;


                        Log.i("geny", "result = " + PointBean.toString());
                    }

                    @Override
                    public void dataError(int type, String msg) {
                        Log.i("geny", "msg = " + msg);
                    }
                });
        requestPointsTask.start();

    }
}
